def totalSize = 0
def count = 0
def sortByTypeThenName = { a, b ->
    a.isFile() != b.isFile() ? a.isFile() <=> b.isFile() : a.name <=> b.name
}

def rootDir = new File('../gssm')

rootDir.traverse(
	type: groovy.io.FileType.FILES,
	nameFilter: ~/.*\.groovy/,
	// A Closure run before each directory is processed and optionally returning a FileVisitResult value which can be used to control subsequent processing.
	preDir: { if (it.name == '.svn') return groovy.io.FileVisitResult.SKIP_SUBTREE },
	// A Closure run after each directory is processed and optionally returning a FileVisitResult value which can be used to control subsequent processing.
	postDir: { println "Found $count files in $it.name totalling $totalSize bytes"
					totalSize = 0; count = 0 },
	// A boolean indicating that the 'postDir' closure should be applied at the root level
	postRoot: true,
	// 排序
	sort: sortByTypeThenName
) {it -> totalSize += it.size(); count++ }
